<%@ page import="com.tlb.ejb.*,com.tlb.dto.*,com.tlb.web.*,java.util.*" %>
<% 
java.text.SimpleDateFormat toFormat = new java.text.SimpleDateFormat("MM/dd/yy hh:mm a");
String parDate = "";

Poster p = new AuthManager(request, response).hardAuthenticatePoster();


int postId = 0;
int treeId = 0;
int threadId = 0;
int x = 0;



try {
    if(request.getParameter("postId") == null || request.getParameter("postId").trim().equals(""))
        throw new Exception("Null postId passed");
    postId = Integer.parseInt(request.getParameter("postId"));
    if(postId < 1)
        throw new Exception("Invalid postId passed: " + postId);
} catch(Exception e) {    
        out.println("Reply Start Error (PostId): " + e.getMessage());
        out.flush();
        return;
}

try {
    if(request.getParameter("treeId") == null || request.getParameter("treeId").trim().equals(""))
        throw new Exception("Null treeId passed");
    treeId = Integer.parseInt(request.getParameter("treeId"));
    if(treeId < 0)
        throw new Exception("Invalid treeId passed: " + treeId);
} catch(Exception e) {    
        out.println("Reply Start Error (treeId): " + e.getMessage());
        out.flush();
        return;
}

try {
    if(request.getParameter("threadId") == null || request.getParameter("threadId").trim().equals(""))
        throw new Exception("Null threadId passed");
    threadId = Integer.parseInt(request.getParameter("threadId"));
    if(threadId < 1)
        throw new Exception("Invalid threadId passed: " + threadId);
} catch(Exception e) {    
        out.println("Reply Start Error (threadId): " + e.getMessage());
        out.flush();
        return;
}

try {
    if(request.getParameter("x") == null || request.getParameter("x").trim().equals(""))
        throw new Exception("Null x passed");
    x = Integer.parseInt(request.getParameter("x"));
    if(x < 1)
        throw new Exception("Invalid x passed: " + x);
} catch(Exception e) {    
        out.println("Reply Start Error (x): " + e.getMessage());
        out.flush();
        return;
}



ThreadDAO tdao = new ThreadDAO();
PostContent pc = (PostContent)(tdao.getPostById(postId));
pc.setContent(pc.getContent().replaceAll("\n", "<p>"));
//pc.setContent(pc.getContent().replaceAll("(?i)([fh]t+ps?://[^ \n\r]+)", "<a href='$1' target=new>$1</a>"));            
pc.setContent(pc.getContent().replaceAll("(?i)([fh]t+ps?://[^ )\"'\n\r]+)", "<a href='$1' target=new>$1</a>"));            

try {
    parDate = toFormat.format(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm").parse(pc.getPost().getPostDate().substring(0,16)));
} catch(Exception e) {    
    parDate = "Parse Error: " + e.getMessage();
}


%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <title>Big<%=Util.getUtil().getBoard(request)==Util.BCB?"College":"Law"%>Board.com</title>
        <link rel="stylesheet" type="text/css" href="ext/tlbStyle.css" />
        <link rel="shortcut icon" href="ext/c_sailboat.gif">
        <script type="text/javascript" src="ext/tlbMenu.js" />
        <script type="text/javascript">
		window.onload = initLeftMenu;
        </script>
        <script>
            function submitReply(form) {
	    	document.getElementById('replyBtn').disabled=true;
	    	form.submit();
	    }            
        </script>
    </head>
    
    <body >
        <center>
        <div id="mainContainer">
            <table>
                
                <tr>
                    <td valign="top">
                        
                        <div id="contentContainer" style="background-color:#FFFFFF">
                        <h1>Reply</h1>
                        
                        <div style="font-family:Times New Roman,MS Sans Serif;font-size:medium;px">
                            <b>Author:</b> <%= pc.getMoniker().getName() %> [<%= pc.getMoniker().getPostCount() %>] (<i><%= pc.getMoniker().getTagLine() %></i>)
                            <br>
                            <b>Posted:</b> <%= parDate %>
                            <br><br>
                            <%= pc.getContent() %>
                            
                            
                            <br>
                            <hr noshade size=1 width="100%">
                            <br>
                            
                            <div id="replyTemplate">
                                <form method=post action=replyPost.jsp>
                                    <input type=hidden name=replyPostId id=replyPostId value="<%= postId %>">
                                    <input type=hidden name=threadId value="<%= threadId %>">
                                    <input type=hidden name=treeId value="<%= treeId %>">
                                    <input type=hidden name=x value="<%= x %>">
                                    <table width=100% border=0>
                                        <tr>
                                            <td width=75><b>Moniker: </b></td>
                                            <td>
                                                <select name="monikerId">
                                                    <option default value="<%= p.getPrimaryMoniker().getMonikerId() %>"><%= p.getPrimaryMoniker().getName() %></option>
                                                    <%
                                                    Set mons = p.getMonikers();
                                                    mons.remove(p.getPrimaryMoniker());
                                                    if(mons.size() > 0){
                                                        for(Iterator it = mons.iterator(); it.hasNext();) {
                                                            Moniker mon = (Moniker)it.next();
                                                            if(mon.getName().equals("Guest"))
                                                                continue;
                                                    %><option value="<%= mon.getMonikerId() %>"><%= mon.getName() %></option>
                                                    <%
                                                        }
                                                    }
                                                    %>
                                                </select>&nbsp;<b>NSFW?</b> <input type=checkbox name=nsfw value=true> 
                                            </td>
                                        </tr>
                                        <tr><td valign=top><b>Post: </b></td><td><textarea rows=10 cols=60 wrap=virtual name=content></textarea></td></tr>
                                        <tr><td>&nbsp;</td><td><input onclick="submitReply(this.form)" type=button class=btn id="replyBtn" value="Save Reply">&nbsp;<input type=button class=btn value="Cancel" 
                                        onclick="javascript: document.location='viewThread.jsp?threadId=<%= threadId %>&x=<%= x %>'"></td></tr>
                                    </table>
                                </form>
                            </div>
                            
                            
                            
                            
                            
                        </div>
                    </td>
                </tr>
            </table>
            
        </div>
        </center>     
        <!-- Start of StatCounter Code -->
        <script type="text/javascript">
var sc_project=2753481; 
var sc_invisible=0; 
var sc_partition=27; 
var sc_security="fadeb289"; 
        </script>
        <script type="text/javascript" src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div class="statcounter"><a class="statcounter" href="http://www.statcounter.com/"><img class="statcounter" src="http://c28.statcounter.com/2753481/0/fadeb289/0/" alt="blog stats" /></a></div></noscript>
        <!-- End of StatCounter Code -->
        
    </body>
</html>